<template name='goodsMarkRecord'>

<view style="display: flex;    height: 100%;">
	<!-- 商品信息-右边 -->
	<view class="box-infos font12  " >
		<!-- 内容体 -->
		<view class="content-box " :style="{height:OnPageSearch==undefined || OnPageSearch==''?'':'100%'} ">
			<!-- 足迹记录 -->
				<view class="boxsss100"  v-if="PostType=='getGoodsMarkRecord'">
					<!-- 增加、删除 -->
					<view class="top-but menu-scroll-w" v-if="(OnPageSearch==undefined || OnPageSearch=='') && PostType !='getGoodsCheck'">
						<view class="top-but-box">
							<!-- 搜索 -->
							<view class="searchBox floatleft">
								<view class="riskTitle">模糊搜索:</view>
								<input
								v-model="search.word" 
								placeholder="输入客户档口 人名 手机 拼音进行搜索"
								placeholder-class="placeholder-class"
								@confirm="loadData(true)"
								class="search-ipu w200"
								:focus="focus.word"
								@blur="focus.word=false"
								/>
								<view class="delete-ipu" v-if="search.word!=''" @click="search.word='',focus.word=true">
									<img src="../../static/img/delete-1.png"></img>
								</view>
							</view>
							<view @click="$common.noMultipleClicks('loadData',loadData,true)" 
							class="rightButttom" >
								<img src="../../static/img/search.png" class="ico" ></img>
								刷新
							</view>
						</view>
					</view>
					<table v-if="resData.list!=undefined && resData.list.length>0">
						<!-- 表头 -->
						<thead>
							<tr >
								<th  class="centers ">
									序
								</th>
								<th  class="centers " >
									账号
								</th>
								<th  class="centers  ">
									商品
								</th>
								<th  class="centers  ">
									数量
								</th>
								<th  class="centers  ">
									时间
								</th>
							</tr>
						</thead>
						<tbody>
							<!-- 内容 -->
							<tr v-for="(item,index) in resData.list" :key="index"
							@click="TabcheckedIndex = index"
							:class="TabcheckedIndex == index ? 'goods-list-select':''"
							>
								<td selectable="true"   class="centers ">
									{{index+1}}
								</td>
								<td selectable="true"   class="centers  cursor" 
								@click="openUser(item.user_id,item.name)"
								>
									{{item.name}}
								</td>
								<td selectable="true"   class="centers  cursor" 
								@click="openGoods(item.goods.id,item.goods.name)"
								>
									{{item.goods.name}}
								</td>
								<td selectable="true"   :class="item.count<=0 ? 'ff2626':''" class="centers ">
									{{item.count}}
								</td>
								<td selectable="true"   class="centers ">
									{{item.date}}
								</td>
							</tr>
						</tbody>
					</table>
					
					<!-- 暂无数据 -->
					<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
					<!-- end -->
				</view>
				
			
			
			<!-- 盘点记录 -->
			<view class="swiper" v-if="PostType=='getGoodsCheck'">
				<view class="box " :class="checkGoodsIndex==0 ? 'select':'m'" @click="checkGoodsIndex=0,loadData(true)">
					等待审核
				</view>
				<view class="box " :class="checkGoodsIndex==1 ? 'select':'m'" @click="checkGoodsIndex=1,loadData(true)">
					审核通过
				</view>
			</view>
			
			
				<view class="boxsss100" v-if="PostType=='getGoodsCheck'">
					<table v-if="resData.list!=undefined && resData.list.length>0">
						<!-- 表头 -->
						<thead>
							<tr >
								<th  class="centers ">
									序
								</th>
								<th  class="centers " >
									提交盘点账号
								</th>
								<th  class="centers  ">
									商品
								</th>
								<th  class="centers  ">
									原库存数量
								</th>
								<th  class="centers  ">
									新盘点数量
								</th>
								<th  class="centers  ">
									库存差异
								</th>
								<th  class="centers  " >
									成本差异
								</th>
								<th  class="centers  ">
									时间
								</th>
								<th  class="centers  "v-if="checkGoodsIndex==1">
									审核账号
								</th>
								<th  class="centers  " v-if="checkGoodsIndex==0">
									操作
								</th>
							</tr>
						</thead>
						<tbody>
							<!-- 内容 -->
							<tr v-for="(item,index) in resData.list"
							:key="index"
							@click="TabcheckedIndex = index"
							:class="TabcheckedIndex == index ? 'goods-list-select':''"
							>
								<td selectable="true"   class="centers ">
									{{index+1}}
								</td>
								<td selectable="true"   class="centers alter cursor" 
								>
									<text @click="openUser(item.user_id,user_name)">{{item.user_name}}</text>
								</td>
								<td selectable="true"   class="centers alter cursor" 
								>
									<text @click="openGoods(item.goods_id,item.goods_name)">{{item.goods_name}}</text>
								</td>
								<td selectable="true"   class="centers ">
									{{item.bare_money}}
								</td>
								<td selectable="true"   class="centers ">
									<input
									:auto-height="true"
									v-model="item.counts" 
									@confirm="$routeData.updateMargin(item.goods_id,item.counts)"
									class="centers "
									:class="item.counts<=0 ? 'ff2626':''" 
									/>
								</td>
								<td selectable="true"   class="centers ">
									{{item.counts - item.bare_money}}
								</td>
								<td selectable="true"   class="centers ">
									{{(item.pifajia - item.money).toFixed(2)}}
								</td>
								
								<td selectable="true"   class="centers ">
									{{item.date}}
								</td>
								
								<td selectable="true"   class="centers "
								 v-if="checkGoodsIndex==1"
								 >
									{{item.uid_name}}
								</td>
								
								<td selectable="true"  
								 v-if="checkGoodsIndex==0"
								@click="deleteCheckGoods(index)"
								class="centers  cursor ff2626">
									删除
								</td>
							</tr>
						</tbody>
					</table>
					
					<!-- 暂无数据 -->
					<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
					<!-- end -->
				</view>
				<view class="checkGoodsSend cursor" v-if="PostType=='getGoodsCheck' && resData.list.length>0 && checkGoodsIndex==0">
					<view class="but" @click="$common.noMultipleClicks('sendMargin',sendMargin)" >以上记录审核为通过</view>
				</view>
			
			<!-- end -->
			
			<!-- 回货记录 -->
			
				<view class="boxsss100" v-if="PostType=='getReplenishStock'">
					<!-- 增加、删除 -->
					<view class="top-but menu-scroll-w" v-if="(OnPageSearch==undefined || OnPageSearch=='') && PostType !='getGoodsCheck'">
						<view class="top-but-box">
					
							<!-- 搜索 -->
							<view class="searchBox floatleft">
								<view class="riskTitle">模糊搜索:</view>
								<input
								v-model="search.word" 
								placeholder="输入客户档口 人名 手机 拼音进行搜索"
								placeholder-class="placeholder-class"
								@confirm="loadData(true)"
								class="search-ipu w200"
								:focus="focus.word"
								@blur="focus.word=false"
								/>
								<view class="delete-ipu" v-if="search.word!=''" @click="search.word='',focus.word=true">
									<img src="../../static/img/delete-1.png"></img>
								</view>
							</view>
							<view @click="$common.noMultipleClicks('loadData',loadData,true)" 
							class="rightButttom" >
								<img src="../../static/img/search.png" class="ico" ></img>
								刷新
							</view>
						
						</view>
					</view>
					<table v-if="resData.list!=undefined && resData.list.length>0">
						<!-- 表头 -->
						<thead>
							<tr >
								<th  class="centers ">
									序
								</th>
								<th class="centers " >
									账号
								</th>
								<th class="  ">
									商品
								</th>
								<th  class="centers  ">
									数量
								</th>
								<th  class="centers  ">
									时间
								</th>
							</tr>
						</thead>
						<tbody>
							<!-- 内容 -->
							<tr v-for="(item,index) in resData.list"
							:key="index"
							@click="TabcheckedIndex = index"
							:class="TabcheckedIndex == index ? 'goods-list-select':''"
							>
								<td selectable="true"   class="centers ">
									{{index+1}}
								</td>
								<td selectable="true" class="centers  cursor alter" >
									<text @click="openUser(item.user_id,user_name)">{{item.user_name}}</text>
								</td>
								<td selectable="true"  class="cursor alter" >
									<text @click="openGoods(item.goods_id,item.goods_name)">{{item.goods_name}}</text>
								</td>
								<td selectable="true"   :class="item.counts<=0 ? 'ff2626':''" class="centers ">
									{{item.counts}}
								</td>
								<td selectable="true"   class="centers ">
									{{item.date}}
								</td>
								
							</tr>
						</tbody>
					</table>
					
					<!-- 暂无数据 -->
					<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
					<!-- end -->
				</view>
			
			
			
			<!-- 降价记录 -->
			
				<view class="boxsss100" v-if="PostType=='getUpdateMoney'">
					<!-- 增加、删除 -->
					<view class="top-but menu-scroll-w" v-if="(OnPageSearch==undefined || OnPageSearch=='') && PostType !='getGoodsCheck'">
						<view class="top-but-box">
					
							<!-- 搜索 -->
							<view class="searchBox floatleft">
								<view class="riskTitle">模糊搜索:</view>
								<input
								v-model="search.word" 
								placeholder="输入客户档口 人名 手机 拼音进行搜索"
								placeholder-class="placeholder-class"
								@confirm="loadData(true)"
								class="search-ipu w200"
								:focus="focus.word"
								@blur="focus.word=false"
								/>
								<view class="delete-ipu" v-if="search.word!=''" @click="search.word='',focus.word=true">
									<img src="../../static/img/delete-1.png"></img>
								</view>
							</view>
							<view @click="$common.noMultipleClicks('loadData',loadData,true)" 
							class="rightButttom" >
								<img src="../../static/img/search.png" class="ico" ></img>
								刷新
							</view>
						
						</view>
					</view>
					<table v-if="resData.list!=undefined && resData.list.length>0">
						<!-- 表头 -->
						<thead>
							<tr >
								<th  class="centers ">
									序
								</th>
								<th class="  ">
									商品
								</th>
								<th  class="centers  ">
									原批发价
								</th>
								<th  class="centers  ">
									批发价
								</th>
								<th  class="centers  ">
									降价百分比
								</th>
								<th  class="centers  ">
									操作者
								</th>
								<th  class="centers  ">
									时间
								</th>
							</tr>
						</thead>
						<tbody>
							<!-- 内容 -->
							<tr v-for="(item,index) in resData.list"
							:key="index"
							@click="TabcheckedIndex = index"
							:class="TabcheckedIndex == index ? 'goods-list-select':''"
							>
								<td selectable="true"   class="centers ">
									{{index+1}}
								</td>
								<td selectable="true"  class="cursor alter" >
									<text @click="openGoods(item.goods_id,item.goods_name)">{{item.goods_name}}</text>
								</td>
								<td selectable="true"   class="centers ">
									{{item.money}}
								</td>
								<td selectable="true"   :class="item.money>item.sum_money ? 'ff2626':''" class="centers ">
									{{item.sum_money}}
								</td>
								<td selectable="true"  v-if="item.money>0" :class="item.money>item.sum_money ? 'ff2626':''" class="centers ">
									{{Math.round((100- (item.sum_money / item.money*100)) * 100) / 100}}%
								</td>
								<td selectable="true" v-else  :class="item.money>item.sum_money ? 'ff2626':''" class="centers ">
									-{{item.sum_money}}%
								</td>
								<td selectable="true"  class="centers ">
									<text @click="openUser(item.user_id,user_name)">{{item.user_name}}</text>
								</td>
								<td selectable="true"   class="centers ">
									{{item.date}}
								</td>
							</tr>
						</tbody>
					</table>
					
					<!-- 暂无数据 -->
					<empty v-if="resData.list==undefined || resData.list.length==0"></empty>
					<!-- end -->
				</view>
			
			
			<pages 
			:current="page.nowPage"
			:sum="page.sum"
			@updatePage="updatePage"
			v-if="OnPageSearch==undefined || OnPageSearch==''"
			></pages>
			<!-- end -->
		</view>

		<!-- 用户详情页 -->
		<uni-popup ref="page_admin" type="center" :title="pageSend.name">
			<person_admin :OnPageSearchUserId="pageSend.id" status="firm_user_list" class="page-boxs h100"></person_admin>	
		</uni-popup>
		<!-- end -->
		
		<!-- 商品页面 -->
		<uni-popup ref="pageGoods" type="center" :title="pageSend.name">
			<shopping_admin :isPop="false" :OnPageSearchGoodsId="pageSend.id"  class="h100"></shopping_admin>
		</uni-popup>
		<!-- end -->
	</view>


</view>
</template>

<script>

	import pages from "@/components/admin-components/pages.vue"
	import empty from "@/components/admin-components/empty.vue"
	//import person_admin from "@/components/user/list.vue"
	import shopping_admin from "@/components/goods/goods.vue"
	export default{
		name:'goodsMarkRecord',
		components: {
			pages,
			empty,shopping_admin
		},
		beforeCreate(){
			this.$options.components.person_admin = require('@/components/user/list.vue').default 
		},
		data(){
			return{
				pagesCreatedSuccess:false,//页面是否创建完毕
				checkGoodsIndex:0,//盘点的状态
				TabcheckedIndex:-1,//当前选中项
				focus:{
					word:false
				},
				pageSend:{//欲要传递到权限页面搜寻的内容
					id:'',//可能是user_id,goods_id
					name:''
				},
				search:{
					word:'',
					user_id:''
				},
				page:{
					
					nowPage:1,//当前页数
					pageCount:1,//总页数
					maxCount:0,
					sum:0,
					pageCounts:15,
				},
				
				resData:{
					list:[]
				},
			}
		},
		 // 此处定义传入的数据
		props: {
		    OnPageSearch: '',//其他页面传递进来直接搜寻的，不是菜单打开的
			/**
			 * 其他页面传递进来直接搜寻的，不是菜单打开的!默认浏览记录
			*/
			PostType: {
				type:String,
				default :'getGoodsMarkRecord'
			},
		},
		beforeUpdate(){
			
		},
		created() {
			let that = this
			if(that.OnPageSearch != undefined && that.OnPageSearch != ''){
				that.search.user_id = that.OnPageSearch
			}
			//console.log("that.OnPageSearch",that.OnPageSearch)
			that.loadData(true);
			
		},
		onShow() {
			
			/* if(this.pagesCreatedSuccess == true){
				this.loadData(true);
			} */
		},
		methods:{
			/**
			 * 草稿单-审核通
			*/
			sendMargin(){
				var that = this
			
				var arr = [];
				for(var i=0;i<that.resData.list.length;i++){
					arr.push(that.resData.list[i].order_id)
				}

				var jsonData = JSON.stringify(arr)
				that.$common.get_request(
					{
						type:'sendMargin',
						json_data:jsonData,
					},
					(res)=>{
						
						that.$common.toast('成功')
						that.loadData(true)
					}
				);
			},
			/**
			 * 盘点记录 删除
			 * 
			*/
			deleteCheckGoods(index){
				var that = this
				var order_id = this.resData.list[index].order_id
				
				uni.showModal({
					content: '是否确定删除？此操作不可逆。删除后有关信息无法恢复！',
					success: function (res) {
						if (res.confirm) {
							that.$common.get_request(
								{
									type:'deleteGoodsCheck',
									order_id:order_id
								},
								(res)=>{
									that.resData.list.splice(index,1)
									that.$common.toast(res.msg)
								}
							);
						}
					}
				});
			},
			/**
			 * 打开商品界面
			*/
			openGoods(goods_id,goods_name){
				this.pageSend.id = goods_id
				this.pageSend.name = goods_name
				this.$refs.pageGoods.open()
			},
			/**
			 * 打开用户界面
			*/
			openUser(uid,name){
				this.pageSend.id = uid
				this.pageSend.name = name
				this.$refs.page_admin.open()
			},
			/**
			 * 分页器回调
			*/
			updatePage(pageName,pageCount){
				var that = this
				that.page.nowPage = pageName
				that.page.pageCounts = pageCount
				that.loadData(false)
			},
			/**
			 * 查看线路
			*/
			onclickRoute(id){
				let tmpArr = this.$routeData.getRoute()
				
				for (var i=0;i<tmpArr.length;i++) {
					if(tmpArr[i].value == id){
						return tmpArr[i].text
					}
				}
				return '-'
			},
		
			/**
			 * 选择线路后回调返回
			*/
			formsubmit(e){
				this.search.word  = ''
				this.page.nowPage = 1//初始化页码
				this.loadData(true)
			},
			/**
			 * 读取
			 * type : goods_list|goods_search
			*/
			loadData(isUpdatePage=true){
				var that = this
				
				that.page.nowPage = isUpdatePage == true ? 1:that.page.nowPage;
				that.$common.get_request(
					{
						type:that.PostType,
						search:that.search.word,//搜索内容
						pages:that.page.nowPage,//当前位于页数
						page_count:that.page.pageCounts,//当前请求页的数量
						user_id:that.search.user_id,
						checkStatus:that.checkGoodsIndex
					},
					
					(res)=>{
						
						that.page.sum  = res.sum
						if(isUpdatePage == true){
						that.page.nowPage  = 1
						}
						
						
						//加入线路的名称
						for (var i=0;i<res.list.length;i++) {
							res.list[i].route_name = that.onclickRoute(res.list[i].route_id)
						}
						
						that.resData = res
					}
				);
				that.pagesCreatedSuccess = true
			},
			
			
		}
	}
</script>

<style>
	.pagesBox{
		display: flex;
		margin: 10px;
		font-size: 14px;
	}

	.swiper{
		display: flex;
		background-color: #f5f7fa;
		text-align: center;
		cursor: pointer;
		margin-left: 10px;
		margin-right: auto;
	}
	.swiper .box{
		font-size: 14px;
		padding: 0px 20px;
		justify-content: center;
		display: flex;
		flex-direction: column;
	}

	.swiper  .m{
		background-color: #fff;
	}
	.swiper .box:hover,.swiper  .select{
		background-color: #0060b9;
		color: #ffff;
		font-weight: 400;
	}
	.checkGoodsSend{
		background-color: #fff;
		padding: 10px 0px;
		margin-right: auto;
		margin-left: 10px;
	}
	.checkGoodsSend .but{
		background-color: #0060b9;
		color: #ffff;
		font-weight: 400;
		font-size: 14px;
		padding: 5px 20px;
	}
</style>
